﻿namespace Arms.Presentation.Web.Areas.Products.Controllers
{
    using Arms.Application.Modules.Products;
    using Arms.Framework.Validators;
    using Arms.Presentation.Web.Controllers;
    using Kendo.Mvc.UI;
    using Kendo.Mvc.Extensions;
    using System.Web.Mvc;

    public class ProductController : BaseController
    {
        private readonly IProductQueryService _service;
        public ProductController(IProductQueryService service)
        {
            _service = Validation.Ensure(service);
        }

        public ActionResult Index()
        {
            return View();
        }

        public ActionResult GetProducts([DataSourceRequest]DataSourceRequest request)
        {
            var products = _service.GetAllProducts();
            ViewData["MenuCategories"] = _service.GetMenuCategories(UserData.AppData.CurrentMenuID);
            ViewData["ProductClasses"] = _service.GetProductClasses();
            ViewData["ProductSubClasses"] = _service.GetProductSubClasses();
            return Json(products.ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
        }
    }
}
